package com.briup.reggie.util;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;

public class AliyunSmsUtil {

    // 你的阿里云访问密钥 ID
    private static final String ACCESS_KEY_ID = "LTAI5t88LHaL465f7FAQwX5W";
    // 你的阿里云访问密钥密码
    private static final String ACCESS_KEY_SECRET = "mApNoRNMW6sglQrFtJAxwQalD7Teow";

    public static boolean sendMsg( String signName, String templateCode,String phoneNumber, String Param) {
        try {
            Config config = new Config()
                    .setAccessKeyId(ACCESS_KEY_ID)
                    .setAccessKeySecret(ACCESS_KEY_SECRET);
            // 访问的域名
            config.endpoint = "dysmsapi.aliyuncs.com";
            Client client = new Client(config);
            SendSmsRequest sendSmsRequest = new SendSmsRequest()
                    .setSignName(signName)
                    .setTemplateCode(templateCode)
                    .setPhoneNumbers(phoneNumber)
                    .setTemplateParam("{\"code\":\"" + Param + "\"}");
            RuntimeOptions runtimeOptions = new RuntimeOptions();
            SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtimeOptions);
            return sendSmsResponse.getBody().getCode().equals("OK");
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}